package no.ntnu.fp.watch.gui;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.ListModel;

import com.cloudgarden.*;
import com.cloudgarden.layout.AnchorConstraint;
import com.cloudgarden.layout.AnchorLayout;

import java.awt.Color;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Vector;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.xml.crypto.Data;

import no.ntnu.fp.model.Database;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class LogFileDialog extends JFrame implements ActionListener{

	private JButton closeButton;
	private JList logFileList;
	private JScrollPane jScrollPane1;
	private JScrollPane jScrollPane2;
	private JTextPane logListHeader;
	private Database database;
	private platformPanel platformPanel;

	public LogFileDialog(platformPanel p){
		this.database = new Database();
		this.platformPanel = p;
		this.initGUI();
		this.setTitle("Log File");
		this.setAlwaysOnTop(true);
		this.setVisible(true);
		this.setSize(1242, 613);
		this.setLocationRelativeTo(null);
		
		
		
	}
	
	private void initGUI() {
		try {
			{
				AnchorLayout thisLayout = new AnchorLayout();
				this.setBounds(0, 0, 1242, 613);
				getContentPane().setLayout(thisLayout);
				this.setResizable(false);
				
				{
					logListHeader = new JTextPane();
					logListHeader.setEditable(false);
					logListHeader.setSelectionColor(Color.white);
					getContentPane().add(logListHeader, new AnchorConstraint(91, 970, 140, 25, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
					logListHeader.setText("                     Time                                                     R                                                   T                                             P                                           EV                                                     dR                                                         Comment");
					logListHeader.setPreferredSize(new java.awt.Dimension(1150, 27));
				}

				{
					closeButton = new JButton();
					getContentPane().add(closeButton, new AnchorConstraint(16, 541, 72, 404, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
					closeButton.setText("Close");
					closeButton.setPreferredSize(new java.awt.Dimension(167, 31));
					
				}
				{
					jScrollPane1 = new JScrollPane();
					getContentPane().add(jScrollPane1, new AnchorConstraint(139, 987, 957, 25, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
					jScrollPane1.setPreferredSize(new java.awt.Dimension(439, 219));
					{
						jScrollPane2 = new JScrollPane();
						jScrollPane1.setViewportView(jScrollPane2);
						jScrollPane2.setPreferredSize(new java.awt.Dimension(446, 287));
						{
						
				
							ArrayList<Vector<Object>> list = database.getAllwellData(this.platformPanel.getPlatform().getCurrentWell().getId());
							for (int i = 0; i < list.size(); i++) {
								list.get(i).add(database.getRealTimeComment((Integer)list.get(i).get(6)));
							}
							LogFilRenderer rend = new LogFilRenderer();
							LogFilModel logFilModel = new LogFilModel(list);
							
							logFileList = new JList(logFilModel);
							jScrollPane2.setViewportView(logFileList);
							jScrollPane2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
							logFileList.setModel(logFilModel);
							//logFileList.setPreferredSize(new java.awt.Dimension(444, 248));
							logFileList.setCellRenderer(rend);
							closeButton.addActionListener(this);
							
						}
					}
				}
				
				
			}
			pack();
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == this.closeButton)
			this.dispose();
	}

}
